const axios = require('axios')
// 1.获取有效token
var getAccess = require('../model/get_access_token')


module.exports = async (req, res, next) => {
	console.log('消息模板',req)
      // 1.拿到一个可用的accessToken
   let accessToken = await getAccess.fetchAccessToken();
   console.log(accessToken);

  axios.post(`https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=${accessToken.access_token}`,
    data = {
      "touser": "okyqpv4JVsuU3CqE3j_lGV8yaNjw",
      "template_id": "wvxy-dZlYXQR71mNrsXsSiTcrNLAfxzLNh6pgDISwtw",
      "url": "https://mp.weixin.qq.com/s/vYGz3SsVGt-D8MvKsKkVdg",
      "data": {
        "first": {
          "value": "恭喜你购买成功！",
          "color": "#173177"
        },
        "keyword1": {
          "value": "巧克力",
          "color": "#173177"
        },
        "keyword2": {
          "value": "39.8元",
          "color": "#f8353d"
        },
        "keyword3": {
          "value": "2014年9月22日",
          "color": "#173177"
        },
        "remark": {
          "value": "欢迎再次购买！",
          "color": "#173177"
        }
      }

    }).then(res => {
      console.log('相应数据', res.data);

    })
  res.send('end')
}